import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";

const routes: RouteRecordRaw[] = [
    {
        path: '/',
        redirect: '/index'
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('../views/login.vue'),
        meta: {
            needTab: false,
            keepAlive:false
        }
    },
    {
        path: '/index',
        name: 'index',
        component: () => import('@/views/index.vue'),
        meta: {
            needTab: true,
            keepAlive:false
        }
    },
    {
        path: '/concernInfo',
        name: 'concernInfo',
        component: () => import('@/views/concernInfo.vue'),
        meta: {
            needTab: true,
            keepAlive:false
        }
    },
    {
        path: '/publish',
        name: 'publish',
        component: () => import('@/views/publish.vue'),
        meta: {
            needTab: true,
            keepAlive:false
        }
    },
    {
        path: '/my',
        name: 'my',
        component: () => import('@/views/my.vue'),
        meta: {
            needTab: true,
            keepAlive:false
        }

    },
    {
        path: '/messageList',
        name: 'messageList',
        component: () => import('@/views/messageList.vue'),
        meta: {
            needTab: true,
            keepAlive:false
        }
    },
    {
        path: '/detailInfo',
        name: 'detailInfo',
        component: () => import('@/views/InfoDetail.vue'),
        meta: {
            needTab: false,
            keepAlive:false
        }
    },
    {
        path: '/userInfo',
        name: 'userInfo',
        component: () => import('@/views/userInfo.vue'),
        meta: {
            needTab: false,
            keepAlive:false
        }
    },
    {
        path: '/ChatInterface',
        name: 'ChatInterface',
        component: () => import('@/views/ChatInterface.vue'),
        meta: {
            needTab: false,
            keepAlive:true
        },
        
    },
    {
        path: '/three',
        name: 'three',
        component: () => import('@/views/Three.vue'),
        meta: {
            needTab: false,
            keepAlive:false
        },
        
    },
    {
        path: '/userMain',
        name: 'userMain',
        component: () => import('@/views/userMain.vue'),
        meta: {
            needTab: false,
            keepAlive:false
        },
        
    },

]

const router = createRouter({
    history: createWebHashHistory(),
    routes: routes
})
//@ts-ignore
router.beforeEach((to, from, next) => {
    if (to.path !== '/login' && !localStorage.getItem('accessToken')) {
        router.push({ path: '/login' })
    }
    next()
})
export default router;
